﻿Imports System.Windows.Forms

Public Class ShippersList

    Public ShipperName As String = ""

    Private Sub OK_Button_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles OK_Button.Click

        'Iterate through the items in the list to determine which shipper was selected
        'from the list (if any) and store the value for later use.
        For Each curNode As Dbi.WinControl.dbiNodeItem In Me.DbiList1.Items

            If curNode.Selected Then

                ShipperName = curNode.Text
                Exit For

            End If

        Next    'Item in the list.

        Me.DialogResult = System.Windows.Forms.DialogResult.OK

        Me.Close()

    End Sub

    Private Sub Cancel_Button_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Cancel_Button.Click
        Me.DialogResult = System.Windows.Forms.DialogResult.Cancel
        Me.Close()
    End Sub

    Private Sub DbiList1_FirstDraw(ByVal sender As Object, ByVal e As System.EventArgs) Handles DbiList1.FirstDraw
        'This event fires when the dbiList control has been drawn for the first time.

        'Prevent the user from selecting more than one item at a time.
        Me.DbiList1.MultiSelect = False

        'Populate the dbiList control with the details of all the shippers stored in the NorthWinds database.
        'Iterate through the Shippers data table.
        For Each curRow As Data.DataRow In dtShippers.Rows

            'Create a new node item to represent the shipper in the list.
            Dim ShipperNode As New Dbi.WinControl.dbiNodeItem(curRow.Item("Company").ToString)
            'Add the item to the Items collection in the list.
            Me.DbiList1.Items.Add(ShipperNode)

        Next

        'Apply the current style selected in the main application to the dbiList control
        Dim curStyle As New dbiWSF.ControlLibrary.dbiWSFStyleControls
        Dim curListOptions As New dbiWSF.ControlLibrary.dbiStylerOptions.dbiListStyleOptions

        curStyle.ImportXMLWithXMLString(curListOptions, Me.DbiList1, dbiWSF.ControlLibrary.dbiStylerOptions.GetResources(curStyleName).dbiListXML)

    End Sub
End Class
